<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class GoodsProduct extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('goods_product');
        if(!$exists){
        $table = $this->table('goods_product', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '商品规格' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('goods_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '商品ID',])
			->addColumn('price', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => true,'comment' => '价格',])
			->addColumn('line_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => true,'comment' => '划线价格',])
			->addColumn('img', 'string', ['limit' => 255,'null' => false,'default' => null,'signed' => true,'comment' => '图片',])
			->addColumn('name', 'string', ['limit' => 50,'null' => false,'default' => null,'signed' => true,'comment' => '名称',])
			->addColumn('stock', 'string', ['limit' => 11,'null' => false,'default' => 0,'signed' => true,'comment' => '库存',])
			->addColumn('weigh', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '权重',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态：0 隐藏、1 正常 、2 商品下架',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
